<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>我的分享</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/dist/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>

<div class="demoTable">
    <button type="button" class="layui-btn layui-btn-primary" id="removeFile">
        <i class="layui-icon">&#xe640;</i>批量取消分享
    </button>

    <div class="layui-inline">
        <input class="layui-input" name="id" id="demoReload" autocomplete="off"> <!--原为name="id"-->
    </div>
    <button class="layui-btn" data-type="reload">搜索</button>           <!--搜索栏目添加-->
</div>

<table class="layui-hide" id="LAY_table_user" lay-filter="user"></table>

<script type="text/html" id="barDemo">
    <a lay-event="cancel" title="取消分享"><i class="layui-icon layui-icon-unlink" style="font-size: 20px;"></i></a>
    <a lay-event="modify" title="修改分享时间"><i class="layui-icon layui-icon-edit" style="font-size: 20px;"></i></a>
</script>

<!--<span th:text="${session.users.realName}"></span>-->

<script type="text/html" id="filenameDev">
    {{#if(d.fileType=='文件夹'){}}
    <i class="glyphicon glyphicon-folder-close" style="color: #0000FF;font-size: 16px"></i>&nbsp;{{d.fileName}}
    {{#}else{}}
    <i class="glyphicon glyphicon-file" style="color: #4cae4c;font-size: 16px"></i>&nbsp;{{d.fileName}}
    {{# }}}
</script>

<script src="layui/dist/layui.js" charset="utf-8"></script>

<script th:inline='none'>
    layui.use('table', function () {
        var table = layui.table;
        var $ = layui.$;
        $("#addFolderDiv").hide();
        //方法级渲染
        table.render({
            elem: '#LAY_table_user'
            , url: 'getAllShareFile'
            , cols: [[
                {checkbox: true, fixed: true}
                , {field: 'fileName', title: '文件名', templet: '#filenameDev', fixed: true}
                , {field: 'fileSize', title: '文件大小', width: 200, sort: true}
                , {field: 'fileType', title: '文件类型', width: 200, sort: true}
                , {field: 'shareTime', title: '最后分享时间', width: 300, sort: true, templet: "<div>{{layui.util.toDateString(d.shareTime,'yyyy-MM-dd HH:mm:ss')}}</div>"}
                , {field: 'remainingTime', title: '设置保留时间（分钟）', width: 200, sort: true}
                , {fixed: 'right',title: '操作', width: 100, align:'center', toolbar: '#barDemo'}
            ]]
            , page: true
            , id: 'testReload'
            , parseData: function (res) {
                console.log(res);
                return {
                    "code": 0,
                    "msg": res.msg,
                    "count": res.count,
                    "data": res.data
                };
            }
        });

        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload');
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        id: demoReload.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $("#addFile").click(function () {
            //页面层
            layer.open({
                type: 1,
                skin: 'layui-layer-rim',
                area: ['500px', '300px'],
                content: $("#addFolderDiv")
            });

        });

        table.on('tool(user)', function(obj){
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if(layEvent === 'cancel'){
                $.ajax({
                    url: 'cancel',
                    type: "get",
                    data: {fileAbsolute: data.fileAbsolute},
                    dataType: "json",
                    success: function (res) {
                            layer.alert(res.msg);
                    }
                })
                table.reload('testReload');
                //window.parent.location.reload();
            }else if(layEvent == 'modify'){
                layer.open({
                    id:1,
                    type: 1,
                    title:'编辑修改时间',
                    skin:'layui-layer-rim',
                    area:['450px', '150px'],

                    content: ' <div class="row" style="width: 420px;  margin-left:5px; margin-top:5px;">'
                        //+'<div class="col-sm-12">'
                        +'<div class="input-group">'
                        +'<span class="input-group-addon"></span>'
                        +'<input id="time_remaining" type="number" class="form-control" placeholder="请输入分享有效时间">'
                        +'</div>'
                        +'</div>'
                    ,
                    btn:['保存','取消'],

                    btn1: function (index,layero) {
                        var time = layero.find('#time_remaining').val();
                            $.ajax({
                                url: 'edit',
                                type: "get",
                                data: {fileAbsolute: data.fileAbsolute, timeRemaining: time},
                                dataType: "json",
                                success: function (res) {
                                    layer.alert(res.url);
                                    table.reload('testReload');
                                    layer.close(index);
                                }
                            })


                    },
                    btn2:function (index,layero) {
                        layer.close(index);
                    }

                });
            }
        });
    });

</script>

</body>
</html>